package com.ikas.ai.server.module.risk.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ikas.ai.handle.JsonResult;
import com.ikas.ai.server.aop.Pageable;
import com.ikas.ai.server.module.AbstractBean;
import com.ikas.ai.server.module.risk.model.dto.RiskReportDisposeDto;
import com.ikas.ai.server.module.risk.model.dto.RiskReportQueryDto;
import com.ikas.ai.server.module.risk.service.RiskReportService;
import com.ikas.ai.server.module.system.model.User;

/**
 * 风险处置报告
 *
 * @author tang.xuandong
 * @version 1.0.0
 * @date 2023/1/31 11:54
 */
@RestController
@RequestMapping("/risk/report")
public class RiskReportController extends AbstractBean {

    @Autowired
    private RiskReportService riskReportService;

    /**
     * 获取风险报告分页数据
     *
     * @param req 风险处置报告分页DTO
     * @return List<RiskReportQueryVo>
     */
    @GetMapping("/page")
    @Pageable(sortType = "desc")
    public JsonResult pageQueryRiskReport(RiskReportQueryDto req) {
        return JsonResult.ok(riskReportService.pageQueryRiskReport(req));
    }

    /**
     * 处置任务
     *
     * @param req RiskReportDisposeDto
     * @return JsonResult
     */
    @PostMapping("/disposeTask")
    public JsonResult disposeTask(@RequestBody @Validated RiskReportDisposeDto req) {
        User user = getUser();
        req.setUpdator(user.getId());
        return JsonResult.ok(riskReportService.disposeTask(req));
    }

    /**
     * 报告详情
     *
     * @param id id
     * @return JsonResult
     */
    @GetMapping("/detail/{id}")
    public JsonResult riskReportDetail(@PathVariable(name = "id") Long id) {
        return JsonResult.ok(riskReportService.riskReportDetail(id));
    }
}
